﻿<UserControl x:Class="ScrumFactory.Tasks.TaskDetail"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:props="clr-namespace:ScrumFactory.Tasks.Properties"
             
             xmlns:SF="clr-namespace:ScrumFactory;assembly=ScrumFactory"
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
             xmlns:SF_Adorners="clr-namespace:ScrumFactory.Windows.Helpers.Adorners;assembly=ScrumFactory.Windows.Helpers"             
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition" 
             xmlns:SF_Ext="clr-namespace:ScrumFactory.Windows.Helpers.Extensions;assembly=ScrumFactory.Windows.Helpers"
             
             x:Name="thisView"
             
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
   
    
    <UserControl.Resources>
        <DataTemplate x:Key="TaskStatusDataTemplate">
            <Grid HorizontalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="20"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Style="{StaticResource TaskStatusImage}"/>
                <TextBlock Grid.Column="1"
                           Text="{Binding ., Converter={StaticResource LocalizeConverter}}"/>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="TaskTypeDataTemplate">
            <Grid HorizontalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="20"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Style="{StaticResource TaskTypeImage}" />
                <TextBlock Grid.Column="1" Text="{Binding ., Converter={StaticResource LocalizeConverter}}"/>
            </Grid>
        </DataTemplate>
    </UserControl.Resources>

    <TabControl Style="{StaticResource WindowTabControl}">
        <TabControl.Items>
            <TabItem Header="{Binding PanelName}">
                <SF_Helpers:PanelLayout Title="{Binding PanelName}" Style="{StaticResource DetailPanelLayout}">

                    <!-- TOOLBAR -->
                    <SF_Helpers:PanelLayout.Toolbar>
                        <ToolBar>

                            <MenuItem Style="{StaticResource GoBackMenuItem}"/>
                            <MenuItem Header="{x:Static props:Resources.Finish_this_task}"
                                    Command="{Binding FinishTaskCommand}"
                                    Style="{StaticResource Toolbar_MenuItemStyleHideWhenDisabled}"
                                    ToolTip="{x:Static props:Resources.Finish_this_task}">
                                <MenuItem.Icon>
                                    <Image Source="/Images/Buttons/check.png" Width="32" Height="32" Stretch="Uniform"/>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Header="{x:Static props:Resources.Copy_tag}"
                                    Command="{Binding CopyTaskTrackIdCommand}"
                                    Style="{StaticResource Toolbar_MenuItemStyleHideWhenDisabled}"
                                    ToolTip="{x:Static props:Resources.Copy_tag_tooltip}">
                                <MenuItem.Icon>
                                    <Image Source="/Images/Toolbar/tag.png" Width="32" Height="32"/>
                                </MenuItem.Icon>
                            </MenuItem>

                            <MenuItem Header="{x:Static props:Resources.Change_log}" Command="{Binding ShowRepositoryLogCommand}">
                                <MenuItem.Icon>
                                    <Image Source="/Images/ToolBar/tail.png" Width="32" Height="32" Stretch="Uniform"/>
                                </MenuItem.Icon>
                            </MenuItem>

                        </ToolBar>
                    </SF_Helpers:PanelLayout.Toolbar>

                    <!-- CONTENT -->
                    <SF_Helpers:PanelLayout.Content>
                        <Grid VerticalAlignment="Stretch">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="160" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width=".3*" MinWidth="100" MaxWidth="220" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>                                
                            </Grid.RowDefinitions>

                            <TextBlock                                       
                            Grid.Column="0" Grid.Row="0"
                            VerticalAlignment="Top"
                            Text="{x:Static props:Resources.Task}"
                            Style="{StaticResource LabelTextBlock}"/>

                            <StackPanel Grid.Column="1"  Grid.Row="0" Orientation="Vertical" Margin="0,0,0,15" >
                                <TextBox                                                                                         
                                Grid.Column="1"  Grid.Row="1"                                                                
                                IsEnabled="{Binding CanEditThisTask}"
                                HorizontalAlignment="Stretch"                        
                                Text="{Binding Task.TaskName, UpdateSourceTrigger=PropertyChanged}"/>
                                <TextBlock Style="{StaticResource LabelTextBlock}" FontWeight="Bold">
                                    <Run Text="{Binding BacklogItem.Name}"/>
                                    <Run Text="{Binding BacklogItem.BacklogItemNumber, StringFormat='{} ({0})'}"/>
                                </TextBlock>
                            </StackPanel>



                            <TextBlock                                       
                            Grid.Column="0" Grid.Row="1" 
                            Text="{x:Static props:Resources.Task_type}"
                            Style="{StaticResource LabelTextBlock}"/>
                            <ComboBox                
                                Grid.Column="1" Grid.Row="1" 
                                IsEnabled="{Binding CanEditThisTask}" MinWidth="220"
                                HorizontalAlignment="Left"                                                                                
                                SelectedValue="{Binding Task.TaskType, Converter={StaticResource EnumToShortConverter}, ConverterParameter={x:Type SF:TaskTypes}, UpdateSourceTrigger=PropertyChanged}"                        
                                ItemTemplate="{StaticResource TaskTypeDataTemplate}"
                                ItemsSource="{Binding Source={StaticResource TaskTypeList}}"/>


                            <TextBlock                                       
                                Grid.Column="0" Grid.Row="2"
                                Text="{x:Static props:Resources.Hours}"
                                Style="{StaticResource LabelTextBlock}"/>
                            <StackPanel Grid.Column="1" Grid.Row="2" Orientation="Horizontal" IsEnabled="{Binding CanEditThisTask}">
                                <StackPanel>
                                    <TextBox Width="70" 
                                 SF_Ext:TextBoxExtension.AutoSelectOnFocus="True" SF_Ext:TextBoxExtension.NumericJumper="0.5"
                                 Text="{Binding Task.PlannedHours, StringFormat='{}{0:0.#}', UpdateSourceTrigger=PropertyChanged}" MaxLength="4" TextAlignment="Right" FontSize="{StaticResource ReallyBigFontSize}" FontWeight="Bold"/>
                                    <TextBlock Text="{x:Static props:Resources.Planned}" Style="{StaticResource LabelTextBlock}" FontSize="{StaticResource TinyFontSize}" HorizontalAlignment="Center"/>
                                </StackPanel>
                                <StackPanel>
                                    <TextBox Width="70" 
                                 SF_Ext:TextBoxExtension.AutoSelectOnFocus="True" SF_Ext:TextBoxExtension.NumericJumper="0.5"
                                 Text="{Binding Task.EffectiveHours, StringFormat='{}{0:0.#}', UpdateSourceTrigger=PropertyChanged}" MaxLength="4" TextAlignment="Right" FontSize="{StaticResource ReallyBigFontSize}" FontWeight="Bold"/>
                                    <TextBlock Text="{x:Static props:Resources.Real}" Style="{StaticResource LabelTextBlock}" FontSize="{StaticResource TinyFontSize}"  HorizontalAlignment="Center"/>
                                </StackPanel>
                            </StackPanel>


                            <TextBlock                          
                            Grid.Column="0" Grid.Row="3"
                            Text="{x:Static props:Resources.Status}"                        
                            Style="{StaticResource LabelTextBlock}"/>
                            <StackPanel Grid.Column="1" Grid.Row="3" Orientation="Horizontal" IsEnabled="{Binding CanEditThisTask}">
                                <ComboBox                                      
                                HorizontalAlignment="Left"                                                                           
                                SelectedValue="{Binding Task_Status, Converter={StaticResource EnumToShortConverter}, ConverterParameter={x:Type SF:TaskStatus}, UpdateSourceTrigger=PropertyChanged}"                        
                                MinWidth="220"
                                ItemTemplate="{StaticResource TaskStatusDataTemplate}"
                                ItemsSource="{Binding Source={StaticResource TaskStatusList}}"/>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{x:Static props:Resources.started_at}" Style="{StaticResource LabelTextBlock}"/>
                                    <DatePicker SelectedDate="{Binding TaskStartDate, UpdateSourceTrigger=PropertyChanged}" />
                                    <TextBlock Text="{x:Static props:Resources.finished_at}" Style="{StaticResource LabelTextBlock}"/>
                                    <DatePicker SelectedDate="{Binding TaskEndDate, UpdateSourceTrigger=PropertyChanged}" />
                                </StackPanel>
                            </StackPanel>

                            <TextBlock
                            Style="{StaticResource LabelTextBlock}"
                            FontSize="{StaticResource SmallFontSize}" FontStyle="Italic"
                            Grid.Column="1" Grid.Row="4">
                            <Run Text="{Binding Task.CreatedAt, StringFormat={x:Static props:Resources.created_at_N}}"/>
                            <Run Text="{Binding Task.TaskOwnerUId, StringFormat={x:Static props:Resources.by_N}}"/>
                            </TextBlock>

                            <TextBlock                                       
                                Grid.Column="0" Grid.Row="5"
                                VerticalAlignment="Top"
                                Text="{x:Static props:Resources.Description}"
                                Style="{StaticResource LabelTextBlock}"/>

                            <TextBox                                                                                         
                                Grid.Column="1"  Grid.Row="5"                                                                
                                IsEnabled="{Binding CanEditThisTask}"
                                HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                                AcceptsReturn="True" TextWrapping="Wrap" 
                                MaxLength="4000"
                                Text="{Binding TaskDetail, UpdateSourceTrigger=PropertyChanged}"/>
                                                           
                            <StackPanel
                                Grid.Column="2" Grid.RowSpan="6"
                                Orientation="Vertical">
                                <TextBlock                                                                          
                                    Text="{x:Static props:Resources.Assignee}" HorizontalAlignment="Center"
                                    Style="{StaticResource LabelTextBlock}"/>                                
                                <ComboBox                                                    
                                    IsEnabled="{Binding CanChangeAssignee}" 
                                    Style="{StaticResource TaskAssigneeComboBoxWithImage}"                                    
                                    HorizontalAlignment="Center" MinWidth="60" MinHeight="60"
                                    SelectedValuePath="MemberUId" SelectedValue="{Binding TaskAssigneeUId}"
                                    ItemsSource="{Binding ProjectMembers}"/>
                                <TextBlock                                                                          
                                    Text="{x:Static props:Resources.as_}" HorizontalAlignment="Center"
                                    Style="{StaticResource LabelTextBlock}"/>                                
                                <ComboBox                                                    
                                    IsEnabled="{Binding CanChangeAssignee}" BorderBrush="Transparent"
                                    MinWidth="130" HorizontalAlignment="Center"
                                    DisplayMemberPath="RoleName"                                                                 
                                    SelectedItem="{Binding TaskRole}"
                                    ItemsSource="{Binding ProjectRoles}"/>
                            </StackPanel>





                        </Grid>
                    </SF_Helpers:PanelLayout.Content>

                </SF_Helpers:PanelLayout>
            </TabItem>
           
        </TabControl.Items>
    </TabControl>

</UserControl>
